package com.app.megaprosoft.modyimcarcare;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.megaprosoft.modyimcarcare.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class services extends Activity {
	
	DecimalFormat df = new DecimalFormat("#,###,##0.00");	
	
	Button 		btn1,btn2,Sum,addHole;
	TextView	TextSum,et0,et1,et2,et4,et5,et6,et7,et8,et9,et10,et11,et12,et13,et14,et15,et16,et17,et18,SumAmount;
	CheckBox 	c0,c1,c2,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,checkDis,checkVIP;
	RadioButton rbA,rbB,rbC,rb5,rb6;
	double a0= 0,a= 0,b= 0,d= 0,e= 0,f= 0,g= 0,h= 0,i= 0,j= 0,k= 0,
			l= 0,m= 0,n= 0,o= 0,p= 0,q= 0,r= 0,subSum = 0,finalSum = 0,amount = 0;
	EditText	disc,prom,disBTH,orther1,orther2,orther3;
	connect con = new connect(); 
	ResultSet rs0,rs;
	ResultSet rs2,rs3,rs10;
	Spinner spnDis;
	int timeSum = 0;
	String list0="",list1="",list2="",list4="",list5="",list6="",list7="",list8="",list9="",
			list10="",list11="",list12="",list13="",list14="",list15="",list16="",list17="",list18="",listWax;
	
	String price0="",price1="",price2="",price4="",price5="",price6="",price7="",price8="",price9="",
			price10="",price11="",price12="",price13="",price14="",price15="",price16="",price17="",price18="",
			checkOrther1 = "",checkOrther2 = "",checkOrther3 = "";
	
	int t0,t1,t2,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15;
	
	AlertDialog.Builder dDialog0,dDialog1,dDialog2,dDialog3,dDialog4;
	
	String ServiceID,OID,DisCt,sumDisc="0",sumDiscNull,sumDisBTH="0",sumDisBTHNull,VIPcode,addSer;
	    private int mYear;
	    private int mMonth;
	    private int mDay;
	    
	    String NameInput,company;
	    
	    public static final int REQUEST_CODE = 1;  
	    public static boolean CHECH_ADD = true; 
	    
	ArrayList<String> price = new ArrayList<String>();
	
	String TypeID,RegisterIDS;
	String[] arr ;
	String[] arr2;
	
	String timeHole,sumHole,listHole,priceHole;
	 
	ArrayList<String> Dis = new ArrayList<String>();
	
 
	
	SimpleAdapter AD;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.services);
		
         System.out.println("connect = " + con);
        
         addSer = getIntent().getExtras().getString("addSer");
         NameInput = getIntent().getExtras().getString("name");
 		 company = getIntent().getExtras().getString("CompanyS");
 		OID = getIntent().getExtras().getString("OID");
 		TypeID = getIntent().getExtras().getString("TypeID");
 		RegisterIDS = getIntent().getExtras().getString("RegisterIDS");
 		
         ///test ////
       /** OID = "139201310070001"; **/
         //// last test Delete!!! ///
         
 		dDialog0 = new AlertDialog.Builder(this);
 		dDialog1 = new AlertDialog.Builder(this);
 		dDialog2 = new AlertDialog.Builder(this);
 		dDialog3 = new AlertDialog.Builder(this);
 		dDialog4 = new AlertDialog.Builder(this);
 		
 		orther1();
		orther2();
		orther3();
 		
 		
 		sumDisc = "0";
 		sumDisBTH = "0";
 
 		
		 // ��Ǩ�Ѻ��ä�ԡ������ҧ�
	    	
 		
 		checkDis = ( CheckBox ) this.findViewById ( R.id.checkDis );
 		checkVIP = ( CheckBox ) this.findViewById ( R.id.checkVIP );
 		SumAmount = ( TextView ) this.findViewById ( R.id.SumAmount );
 		
	 		 c0 = ( CheckBox ) this.findViewById ( R.id.check0 );	
	 		 rbA = (RadioButton) this.findViewById ( R.id.rb1 );	
	 		 rbB = (RadioButton) this.findViewById ( R.id.rb2 );	
	 		 rbC = (RadioButton) this.findViewById ( R.id.rb3 );	
			 et0 = ( TextView ) this.findViewById ( R.id.result0 );

			 c1 = ( CheckBox ) this.findViewById ( R.id.check1 );			
			 et1 = ( TextView ) this.findViewById ( R.id.result1 );
			 
			 c2 = ( CheckBox ) this.findViewById ( R.id.check2 );			
			 et2 = ( TextView ) this.findViewById ( R.id.result2 );
			 
		     c4 = ( CheckBox ) this.findViewById ( R.id.check4 );			
			 et4 = ( TextView ) this.findViewById ( R.id.result4 );
				
			
			 c5 = ( CheckBox ) this.findViewById ( R.id.check5 );			
			 et5 = ( TextView ) this.findViewById ( R.id.result5 );
					
			 c6 = ( CheckBox ) this.findViewById ( R.id.check6 );			
			 et6 = ( TextView ) this.findViewById ( R.id.result6 );
			 
			 c7 = ( CheckBox ) this.findViewById ( R.id.check7 );			
			 et7 = ( TextView ) this.findViewById ( R.id.result7 );
					 
			 c8 = ( CheckBox ) this.findViewById ( R.id.check8 );			
			 et8 = ( TextView ) this.findViewById ( R.id.result8 );
			
			 c9 = ( CheckBox ) this.findViewById ( R.id.check9 );			
			 et9 = ( TextView ) this.findViewById ( R.id.result9 );
			 
			 c10 = ( CheckBox ) this.findViewById ( R.id.check10 );			
			 et10 = ( TextView ) this.findViewById ( R.id.result10 );
			 
			 c11 = ( CheckBox ) this.findViewById ( R.id.check11 );			
			 et11 = ( TextView ) this.findViewById ( R.id.result11 );
			 
			 c12 = ( CheckBox ) this.findViewById ( R.id.check12 );			
			 et12 = ( TextView ) this.findViewById ( R.id.result12 );
			 
			 c13 = ( CheckBox ) this.findViewById ( R.id.check13 );			
			 et13 = ( TextView ) this.findViewById ( R.id.result13 );
			 
			 c14 = ( CheckBox ) this.findViewById ( R.id.check14 );			
			 et14 = ( TextView ) this.findViewById ( R.id.result14 );
			 
			 c15 = ( CheckBox ) this.findViewById ( R.id.check15 );			
			 et15 = ( TextView ) this.findViewById ( R.id.result15 );
					 
			 TextSum = (TextView) findViewById(R.id.Sum);
			 Sum = (Button) findViewById(R.id.ButtonSum);
			 
			 disc = (EditText) findViewById(R.id.discount);
			 disBTH = (EditText) findViewById(R.id.disBTH);
			 
			
			 
			 
			 prom = (EditText) findViewById(R.id.VIPcode);			 
			
			 //VIPcode = VIPdis.getText().toString();

			 btn1 = (Button) findViewById(R.id.button1);
			 btn2 = (Button) findViewById(R.id.button2);
			 addHole = (Button) findViewById(R.id.addList);
					
			    	disc.setEnabled(false);
					disBTH.setEnabled(false);
					prom.setEnabled(false);	 
			
					
				btn2.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						//Open Form Add
						btn2.setBackgroundColor(Color.GREEN);
						Intent newActivityAdd = new Intent(services.this,InitialServices.class);
						newActivityAdd.putExtra("name", NameInput);
						newActivityAdd.putExtra("CompanyS", company);
						
						startActivity(newActivityAdd);

					}
					});
				
			
				
		//////////////////////////// Discount //////////////////////////////////
				
				if(addSer.equals("addSer")){
					
					checkDis.setEnabled(false);
					checkVIP.setEnabled(false);
					addHole.setEnabled(false);
					c16.setEnabled(false);
					c17.setEnabled(false); 
					c18.setEnabled(false);
					
					
				}else{
				checkDis.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
		    			if(checkDis.isChecked()){
	
		    				selectDis();
		    			
		    				disc.setEnabled(true);
		    				disBTH.setEnabled(true);
		    				spnDis.setEnabled(true);		    				
		    			
		    				}
		    			else {
		    				
		    				disc.setEnabled(false);
		    				disBTH.setEnabled(false);
		    				sumDisc = "0";
		    				sumDisBTH = "0";
		    				disc.setText("0");
		    				disBTH.setText("0");
		    				Dis.clear();
		    				spnDis.setEnabled(false);
		    				
		    				
		    				}
		    			
		    		
		            }
		        });
				
				
				
				
				/////////////////////////////// Check VIP   ///////////////////////////
					
					checkVIP.setOnClickListener(new View.OnClickListener() {
						//String str;
						@Override
						public void onClick(View v) {
			    			if(checkVIP.isChecked()){
			    				
			    				
			    				 prom.setEnabled(true);	 
			    				 disc.setEnabled(true);
				    			 disBTH.setEnabled(true);

								
			    				}
			    			else {
			    				
	    		
			    				prom.setEnabled(false);	 
			    				disc.setEnabled(false);
			    				disBTH.setEnabled(false);
			    				
			    				sumDisc = "0";
			    				sumDisBTH = "0";
			    				disc.setText("0");
			    				disBTH.setText("0");
			    				
			   				 	prom.setText("");
			   				 	
			    				
			    				}
			    			
			    		
			            }
			        });	
					
					
				}
				
				 
				addHole.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						
						CHECH_ADD = false;
						Intent intent = new Intent(services.this, HoleActivity.class);			
						//intent.setAction(Intent.ACTION_GET_CONTENT);
						//intent.addCategory(Intent.CATEGORY_OPENABLE);
						intent.putExtra("name", NameInput);
						intent.putExtra("CompanyS", company);
						intent.putExtra("addHole", "addHole");
						intent.putExtra("OID", OID);
						intent.putExtra("TypeID", TypeID);
						intent.putExtra("RegisterIDS", RegisterIDS);

						startActivityForResult(intent, REQUEST_CODE); 
					
	    				
					}
					});
				
	///////////////////// sum  ////////////////////////////////
					
					Sum.setOnClickListener(new View.OnClickListener() {
						public void onClick(View v) {
							
							
							
							if(et16.getText().toString().equals("")){
								p = 0;
							}else{
							p = Double.parseDouble(et16.getText().toString());
							}
							
							if(et17.getText().toString().equals("")){
								q = 0;
							}else{
							q = Double.parseDouble(et17.getText().toString());
							}
							
							if(et18.getText().toString().equals("")){
								r = 0;
							}else{
							r = Double.parseDouble(et18.getText().toString());
							}
							
						///////////  ��ǹ ����� ////////////
							
							if(et16.getText().toString().equals("")){
								p = 0;
							}else{
							p = Double.parseDouble(et16.getText().toString());
							}
							
							if(et17.getText().toString().equals("")){
								q = 0;
							}else{
							q = Double.parseDouble(et17.getText().toString());
							}
							
							if(et18.getText().toString().equals("")){
								r = 0;
							}else{
							r = Double.parseDouble(et18.getText().toString());
							}
							
						//////////////  ��ǹŴ�ٻͧ	
							sumDiscNull = disc.getText().toString();
		    				
		    				if(sumDiscNull.equals(null)||sumDiscNull.equals("")){
		    					sumDisc = "0";
		    				}else{
		    					sumDisc = sumDiscNull;
		    				}
		    				sumDisBTHNull = disBTH.getText().toString();
		    				
		    				if(sumDisBTHNull.equals(null)||sumDisBTHNull.equals("")){
		    					sumDisBTH = "0";
		    				}else{
		    					
		    					sumDisBTH = sumDisBTHNull;
		    				}
		    				
		    			////////////////���ǹŴ VIP
		    				VIPcode = prom.getText().toString();
		    				 
		    				 
		    				
	
							
							timeSum = t0+t1+t2+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15;
							timeSum = timeSum+0;
							Toast.makeText(services.this, "All time is : "+timeSum, Toast.LENGTH_SHORT).show();
							
							
							amount = a0+a+b+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r;
							 
							SumAmount.setText(String.valueOf(df.format(amount)));
							
							finalSum = (amount-Integer.parseInt(sumDisBTH))-(((amount-Integer.parseInt(sumDisBTH))*Integer.parseInt(sumDisc))/100);
							
	
		    				TextSum.setText(String.valueOf(df.format(finalSum)));	
		    		
						}
						});
				
				
//					----------------------0-----------------------
					
					
						c0.setOnClickListener(new View.OnClickListener() {
							String str,str1;
							@Override
							public void onClick(View v) {
				    			if(c0.isChecked()){
				    				
				    				dDialog0.setTitle("��س����͡ ");
				    				dDialog0.setIcon(android.R.drawable.btn_star_big_on); 
				    				dDialog0.setMessage("��ͧ�����ҧ�������ͧ�����������");
				    				dDialog0.setPositiveButton("��ҧ�������",
					  					new DialogInterface.OnClickListener() {
				    					
									    public void onClick(DialogInterface dialog,int id) {
										
									    	
				    				
									
									///////////////////////////////////////////////////
									
									dDialog3.setTitle("��س����͡ ");
				    				dDialog3.setIcon(android.R.drawable.btn_star_big_on); 
				    				dDialog3.setMessage("��ͧ�����ꡫ���������");
				    				dDialog3.setPositiveButton("��ͧ���",
					  					  new DialogInterface.OnClickListener() {
									    public void onClick(DialogInterface dialog,int id) {
										
									    	
									rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	    	
				    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110002' ");
				    				try {
				     					rs2.next();
				     					rs3.next();
				    					list0 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
				    					t0 = Integer.parseInt(rs2.getString("Duration").toString())+
				    							Integer.parseInt(rs3.getString("Duration").toString());
				    				} catch (SQLException e1) {
				    					// TODO Auto-generated catch block
				    					e1.printStackTrace();
				    				}
				    				
				    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");
				    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110002' ");		   
									try {

										    rs.next();
										    rs0.next();
										    str = rs.getString("ItemPrice");
										    str1 = rs0.getString("ItemPrice"); // �����
										    //price0 = rs.getString("ItemPrice")+rs0.getString("ItemPrice")+",";
					
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}      
									et0.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
									a0 = Double.parseDouble(str)+Double.parseDouble(str1);
									price0 = str+","+str1+",";
									
									    }
									    });
					            	

				    				dDialog3.setNegativeButton("����ͧ���",
					  					  new DialogInterface.OnClickListener() {
									    public void onClick(DialogInterface dialog,int id) {
									    	
									    	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110002' ");
						    				try {
						     					rs2.next();
						    					list0 = rs2.getString("ItemName")+",";
						    					t0 = Integer.parseInt(rs2.getString("Duration").toString());
						    				} catch (SQLException e1) {
						    					// TODO Auto-generated catch block
						    					e1.printStackTrace();
						    				}
						    				
						    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110002' ");		   
											try {

												    rs.next();
												    str = rs.getString("ItemPrice");
												    price0 = rs.getString("ItemPrice")+",";
							
											} catch (SQLException e) {
												// TODO Auto-generated catch block
												e.printStackTrace();
											}      
											et0.setText(df.format(Double.parseDouble(str)));
											a0 = Double.parseDouble(str);
											    }
											    });
				    				dDialog3.show();
									
				    				
									//////////////////////////////////////////////////
									
									
									    }
									  });
				    				
				    				
				    				
		////////////////////////////////////////////////////////////////////////////////////////////
				    				dDialog0.setNeutralButton("��ҧ��������",
						  					  new DialogInterface.OnClickListener() {
										    public void onClick(DialogInterface dialog,int id) {
										    	
												///////////////////////////////////////////////////
												
												dDialog3.setTitle("��س����͡ ");
							    				dDialog3.setIcon(android.R.drawable.btn_star_big_on); 
							    				dDialog3.setMessage("��ͧ�����ꡫ���������");
							    				dDialog3.setPositiveButton("��ͧ���",
								  					  new DialogInterface.OnClickListener() {
												    public void onClick(DialogInterface dialog,int id) {
													
												    	
												rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	    	
							    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110003' ");
							    				try {
							     					rs2.next();
							     					rs3.next();
							    					list0 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
							    					t0 = Integer.parseInt(rs2.getString("Duration").toString())+
							    							Integer.parseInt(rs3.getString("Duration").toString());
							    				} catch (SQLException e1) {
							    					// TODO Auto-generated catch block
							    					e1.printStackTrace();
							    				}
							    				
							    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");
							    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110003' ");		   
												try {

													    rs.next();
													    rs0.next();
													    str = rs.getString("ItemPrice");
													    str1 = rs0.getString("ItemPrice");
													   // price0 = rs.getString("ItemPrice")+rs0.getString("ItemPrice")+",";
								
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}      
												et0.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
												a0 = Double.parseDouble(str)+Double.parseDouble(str1);
												price0 = str+","+str1+",";
												
												    }
												    });
								            	

							    				dDialog3.setNegativeButton("����ͧ���",
								  					  new DialogInterface.OnClickListener() {
												    public void onClick(DialogInterface dialog,int id) {
												    	
												    	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110003' ");
									    				try {
									     					rs2.next();
									    					list0 = rs2.getString("ItemName")+",";
									    					t0 = Integer.parseInt(rs2.getString("Duration").toString());
									    				} catch (SQLException e1) {
									    					// TODO Auto-generated catch block
									    					e1.printStackTrace();
									    				}
									    				
									    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110003' ");		   
														try {

															    rs.next();
															    str = rs.getString("ItemPrice");
															    price0 = rs.getString("ItemPrice")+",";
										
														} catch (SQLException e) {
															// TODO Auto-generated catch block
															e.printStackTrace();
														}      
														et0.setText(df.format(Double.parseDouble(str)));
														a0 = Double.parseDouble(str);
														    }
														    });
							    				dDialog3.show();
												
							    				
												//////////////////////////////////////////////////
												
												    }
												  });
				    				dDialog0.setNegativeButton("�����ҧ",
						  					  new DialogInterface.OnClickListener() {
										    public void onClick(DialogInterface dialog,int id) {
										    	
												///////////////////////////////////////////////////
												
												dDialog3.setTitle("��س����͡ ");
							    				dDialog3.setIcon(android.R.drawable.btn_star_big_on); 
							    				dDialog3.setMessage("��ͧ�����ꡫ���������");
							    				dDialog3.setPositiveButton("��ͧ���",
								  					  new DialogInterface.OnClickListener() {
												    public void onClick(DialogInterface dialog,int id) {
													
												    	
												rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	    	
							    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110004' ");
							    				try {
							     					rs2.next();
							     					rs3.next();
							    					list0 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
							    					t0 = Integer.parseInt(rs2.getString("Duration").toString())+
							    							Integer.parseInt(rs3.getString("Duration").toString());
							    				} catch (SQLException e1) {
							    					// TODO Auto-generated catch block
							    					e1.printStackTrace();
							    				}
							    				
							    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");
							    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110004' ");		   
												try {

													    rs.next();
													    rs0.next();
													    str = rs.getString("ItemPrice");
													    str1 = rs0.getString("ItemPrice");
													    //price0 = rs.getString("ItemPrice")+rs0.getString("ItemPrice")+",";
								
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}      
												et0.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
												a0 = Double.parseDouble(str)+Double.parseDouble(str1);
												price0 = str + "," + str1 + ",";
												
												    }
												    });
								            	

							    				dDialog3.setNegativeButton("����ͧ���",
								  					  new DialogInterface.OnClickListener() {
												    public void onClick(DialogInterface dialog,int id) {
												    	
												    	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201311110004' ");
									    				try {
									     					rs2.next();
									    					list0 = rs2.getString("ItemName")+",";
									    					t0 = Integer.parseInt(rs2.getString("Duration").toString());
									    				} catch (SQLException e1) {
									    					// TODO Auto-generated catch block
									    					e1.printStackTrace();
									    				}
									    				
									    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311110004' ");		   
														try {

															    rs.next();
															    str = rs.getString("ItemPrice");
															    price0 = rs.getString("ItemPrice")+",";
										
														} catch (SQLException e) {
															// TODO Auto-generated catch block
															e.printStackTrace();
														}      
														et0.setText(df.format(Double.parseDouble(str)));
														a0 = Double.parseDouble(str);
														    }
														    });
							    				dDialog3.show();
												
							    				
												//////////////////////////////////////////////////
												
												
												    }
												  });
				    				dDialog0.show();
				    				}
				    			else {
				    				
				    				t0 = 0;
				    				 a0 = 0;
				    				 list0 = "";
				    				 price0 ="";
				    				et0.setText("");
				    				}
				            }
						});
					
	    	
		  //========= case 1 ============================================================ 	   			 

					
					c1.setOnClickListener(new View.OnClickListener() {
						String str,str1;
						@Override
						public void onClick(View v) {
			    			if(c1.isChecked()){
			    				
			    				dDialog2.setTitle("��س����͡ ");
			    				dDialog2.setIcon(android.R.drawable.btn_star_big_on); 
			    				dDialog2.setMessage("��ͧ�����ꡫ���������");
			    				dDialog2.setPositiveButton("��ͧ���",
				  					new DialogInterface.OnClickListener() {
								    public void onClick(DialogInterface dialog,int id) {
									
								    	/** �ѧ�������� OID�ͧ �������� �Դ�ѭ�� Insert Item �����ѧ��ҹ�����**/
			    				
								    	
								    	
								rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	
			    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310280001' ");
			    				try {
			    					rs2.next();
			    					rs3.next();
			    					
			    					list1 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
			    					t1 = Integer.parseInt(rs2.getString("Duration").toString())+
			    							Integer.parseInt(rs3.getString("Duration").toString());
			    				
			    				} catch (SQLException e1) {
			    					// TODO Auto-generated catch block
			    					e1.printStackTrace();
			    				}
			    			 
			    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");	
			    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310070001' ");		   
								try {
									 
									    rs.next();
									    rs0.next();
										str = rs.getString("ItemPrice");
										str1 = rs0.getString("ItemPrice");
										
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}    
								 
								et1.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
								a = Double.parseDouble(str)+Double.parseDouble(str1);
								price1 = str+","+str1+",";
								    }
								  });
			    				
			    				/////////////////////////////// + waxz /////////////////////
				            	
			    				dDialog2.setNegativeButton("����ͧ���",
					  					  new DialogInterface.OnClickListener() {
									    public void onClick(DialogInterface dialog,int id) {
									    	
									    	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310280001' ");
						    				try {
						    					rs2.next();
						    					list1 = rs2.getString("ItemName")+",";
						    					t1 = Integer.parseInt(rs2.getString("Duration").toString());
						    				
						    				} catch (SQLException e1) {
						    					// TODO Auto-generated catch block
						    					e1.printStackTrace();
						    				}
						    			 
						    				
						    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310070001' ");		   
											try {
												
												    rs.next();
													str = rs.getString("ItemPrice");
													price1 = rs.getString("ItemPrice")+",";
													
											} catch (SQLException e) {
												// TODO Auto-generated catch block
												e.printStackTrace();
											}    
											 
											et1.setText(df.format(Double.parseDouble(str)));
											a = Double.parseDouble(str);
											
											    }
											  });
			    				dDialog2.show();
			    				}
			    			else {
			    				
			    				t1 = 0;
			    				 a = 0;
			    				 list1 = "";
			    				 price1="";
			    				et1.setText("");
			    				}
			            }
			        });
							   //========= case 2 ============================================================ 			  
					
					c2.setOnClickListener(new View.OnClickListener() {
						String str,str1;
						@Override
						public void onClick(View v) {
			    			if(c2.isChecked()){
			    				
			    				
			    					
			    				
						            	
						            	dDialog1.setTitle("��س����͡ ");
						            	dDialog1.setIcon(android.R.drawable.btn_star_big_on); 
						            	dDialog1.setMessage("��ͧ�����ꡫ���������");
						            	dDialog1.setPositiveButton("��ͧ���",
						  					  new DialogInterface.OnClickListener() {
										    public void onClick(DialogInterface dialog,int id) {
											
										    	/** �ѧ�������� OID�ͧ �������� �Դ�ѭ�� Insert Item �����ѧ��ҹ�����**/
										    	rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	
										    	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100001' ");
							    				try {
							    					rs2.next();
							    					rs3.next();
							    					list2 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
							    					t2 = Integer.parseInt(rs2.getString("Duration").toString())+
							    							Integer.parseInt(rs3.getString("Duration").toString());
							    					
							    				} catch (SQLException e1) {
							    					// TODO Auto-generated catch block
							    					e1.printStackTrace();
							    				}
							    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");
							    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100001' ");		   
												try {

													    rs.next();
													    rs0.next();
													    str = rs.getString("ItemPrice");
													    str1 = rs.getString("ItemPrice");
													    
								
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}      
												et2.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
												b = Double.parseDouble(str)+Double.parseDouble(str1);
												price2 = str+","+str1+",";
										    }
										  });

						            	
						          
						            	
						            	
						            	dDialog1.setNegativeButton("����ͧ���",
						  					  new DialogInterface.OnClickListener() {
										    public void onClick(DialogInterface dialog,int id) {


										    	
							    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100001' ");
							    				try {
							    					rs2.next();
							    					list2 = rs2.getString("ItemName")+",";
							    					t2 = Integer.parseInt(rs2.getString("Duration").toString());
							    					
							    				} catch (SQLException e1) {
							    					// TODO Auto-generated catch block
							    					e1.printStackTrace();
							    				}
							    				
							    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100001' ");		   
												try {

													    rs.next();
													    str = rs.getString("ItemPrice");
													    price2 = rs.getString("ItemPrice")+",";
								
												} catch (SQLException e) {
													// TODO Auto-generated catch block
													e.printStackTrace();
												}      
												et2.setText(df.format(Double.parseDouble(str)));
												b = Double.parseDouble(str);
										    }
										  });
						            	dDialog1.show();
			    			
		    	
			    				}
			    			else {
			    				 b = 0;
			    				 t2 = 0;
			    				 list2 = "";
			    				 price2="";
			    				et2.setText("");
			    				}
			            }
			        }); 
		    				
		    
		    //////////////////////////////////////////  3 ////////////////////////////////////				
		    				
					c4.setOnClickListener(new View.OnClickListener() {
						String str,str1;
						@Override
						public void onClick(View v) {
			    			if(c4.isChecked()){
			    				
			    				dDialog4.setTitle("��س����͡ ");
			    				dDialog4.setIcon(android.R.drawable.btn_star_big_on); 
			    				dDialog4.setMessage("��ͧ�����ꡫ���������");
			    				dDialog4.setPositiveButton("��ͧ���",
				  					  new DialogInterface.OnClickListener() {
								    public void onClick(DialogInterface dialog,int id) {
									
								    	/** �ѧ�������� OID�ͧ �������� �Դ�ѭ�� Insert Item �����ѧ��ҹ�����**/
								rs3 = con.selectData("SELECT * FROM Item WHERE OID = '104201311090001' ");    	    	
			    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100003' ");
			    				try {
			    					rs2.next();
			    					rs3.next();
			    					list4 = rs2.getString("ItemName")+","+rs3.getString("ItemName")+",";		
			    					t4 =  Integer.parseInt(rs2.getString("Duration").toString())+
			    							Integer.parseInt(rs3.getString("Duration").toString());
			    				} catch (SQLException e1) {
			    					// TODO Auto-generated catch block
			    					e1.printStackTrace();
			    				}
			    				
			    				rs0 = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201311090001' ");
			    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100003' ");		   
								try {
	 
									    rs.next();
									    rs0.next();
									    str = rs.getString("ItemPrice");
									    str1 = rs0.getString("ItemPrice");
									   
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}      
								et4.setText(df.format(Double.parseDouble(str)+Double.parseDouble(str1)));
								d = Double.parseDouble(str)+Double.parseDouble(str1);
								price4 = str+","+str1+",";
			    				}
				            	});
				            	
				            	
			    				dDialog4.setNegativeButton("����ͧ���",
					  					  new DialogInterface.OnClickListener() {
									    public void onClick(DialogInterface dialog,int id) {
				            	rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100003' ");
			    				try {
			    					rs2.next();
			    					list4 = rs2.getString("ItemName")+",";
			    					t4 = Integer.parseInt(rs2.getString("Duration").toString());
			    				} catch (SQLException e1) {
			    					// TODO Auto-generated catch block
			    					e1.printStackTrace();
			    				}
			    				
			    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100003' ");		   
								try {

									    rs.next();
									    str = rs.getString("ItemPrice");
									    price4 = rs.getString("ItemPrice")+",";
				
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}      
								et4.setText(df.format(Double.parseDouble(str)));
								d = Double.parseDouble(str);
			    				}
				            	});
				            	
			    				dDialog4.show();
				            	
			    			}
			    			else {
			    				t4 = 0;
			    				list4 = "";
			    				price4="";
			    				 d = 0;
			    				et4.setText("");
			    				}
			            }
			        });
	    				
	    				
				c5.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c5.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100004' ");
		    				try {
		    					rs2.next();
		    					list5 = rs2.getString("ItemName")+",";
		    					t5 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100004' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price5 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et5.setText(df.format(Double.parseDouble(str)));
							 e = Double.parseDouble(str);
		    				}
		    			else {
		    				t5 = 0;
		    				list5 = "";
		    				price5="";
		    				 e = 0;
		    				et5.setText("");
		    				}
		            }
		        });
	    				
				c6.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c6.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100005' ");
		    				try {
		    					rs2.next();
		    					list6 = rs2.getString("ItemName")+",";
		    					t6 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100005' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price6 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et6.setText(df.format(Double.parseDouble(str)));
							 f = Double.parseDouble(str);
		    				}
		    			else {
		    				t6 = 0;
		    				list6 = "";
		    				price6="";
		    				 f = 0;
		    				et6.setText("");
		    				}
		            }
		        });
	    				
				c7.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c7.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100006' ");
		    				try {
		    					rs2.next();
		    					list7 = rs2.getString("ItemName")+",";
		    					t7 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100006' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price7 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et7.setText(df.format(Double.parseDouble(str)));
							 g = Double.parseDouble(str);
		    				}
		    			else {
		    				t7 = 0;
		    				list7 = "";
		    				price7="";
		    				 g = 0;
		    				et7.setText("");
		    				}
		            }
		        });
	    				
	    				
				c8.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c8.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100007' ");
		    				try {
		    					rs2.next();
		    					list8 = rs2.getString("ItemName")+",";
		    					t8 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100007' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price8 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et8.setText(df.format(Double.parseDouble(str)));
							 h = Double.parseDouble(str);
		    				}
		    			else {
		    				t8 = 0;
		    				list8 = "";
		    				price8="";
		    				 h = 0;
		    				et8.setText("");
		    				}
		            }
		        });
	    				
				c9.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c9.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100008' ");
		    				try {
		    					rs2.next();
		    					list9 = rs2.getString("ItemName")+",";
		    					t9 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100008' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price9 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
						    et9.setText(df.format(Double.parseDouble(str)));
						    i = Double.parseDouble(str);
							
		    				}
		    			else {
		    				t9 = 0;
		    				list9 = "";
		    				price9="";
		    				 i = 0;
		    				et9.setText("");
		    				}
		            }
		        });
				
				
				c10.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c10.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100009' ");
		    				try {
		    					rs2.next();
		    					list10 = rs2.getString("ItemName")+",";
		    					t10 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100009' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price10 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et10.setText(df.format(Double.parseDouble(str)));
							 j = Double.parseDouble(str);
		    				}
		    			else {
		    				t10 = 0;
		    				list10 = "";
							price10="";
		    				 j = 0;
		    				et10.setText("");
		    				}
		            }
		        });
				
				
				c11.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c11.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100010' ");
		    				try {
		    					rs2.next();
		    					list11 = rs2.getString("ItemName")+",";
		    					t11 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100010' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price11 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et11.setText(df.format(Double.parseDouble(str)));
							 k = Double.parseDouble(str);
		    				}
		    			else {
		    				t11 = 0;
		    				list11 = "";
		    				price11="";
		    				 k = 0;
		    				et11.setText("");
		    				}
		            } 
		        });
				
				
				c12.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c12.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100011' ");
		    				try {
		    					rs2.next();
		    					list12 = rs2.getString("ItemName")+",";
		    					t12 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100011' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price12 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et12.setText(df.format(Double.parseDouble(str)));
							 l = Double.parseDouble(str);
		    				}
		    			else {
		    				t12 = 0;
		    				list12 = "";
		    				price12="";
		    				 l = 0;
		    				et12.setText("");
		    				}
		            }
		        });
				
				
				c13.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c13.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100012' ");
		    				try {
		    					rs2.next();
		    					list13 = rs2.getString("ItemName")+",";
		    					t13 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100012' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price13 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et13.setText(df.format(Double.parseDouble(str)));
							 m = Double.parseDouble(str);
		    				}
		    			else {
		    				t13 = 0;
		    				list13 = "";
		    				price13="";
		    				 m = 0; 
		    				et13.setText("");
		    				}
		            }
		        });
				
				c14.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c14.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100013' ");
		    				try {
		    					rs2.next();
		    					list14 = rs2.getString("ItemName")+",";
		    					t14 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100013' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price14 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et14.setText(df.format(Double.parseDouble(str)));
							 n = Double.parseDouble(str);
		    				}
		    			else {
		    				t14 = 0;
		    				list14 = "";
		    				price14="";
		    				 n = 0;
		    				et14.setText("");
		    				}
		            }
		        });
				
				
				c15.setOnClickListener(new View.OnClickListener() {
					String str;
					@Override
					public void onClick(View v) {
		    			if(c15.isChecked()){
		    				
		    				rs2 = con.selectData("SELECT * FROM Item WHERE OID = '104201310100014' ");
		    				try {
		    					rs2.next();
		    					list15 = rs2.getString("ItemName")+",";
		    					t15 = Integer.parseInt(rs2.getString("Duration").toString());
		    				} catch (SQLException e1) {
		    					// TODO Auto-generated catch block
		    					e1.printStackTrace();
		    				}
		    				
		    				rs = con.selectData("SELECT * FROM ItemPrice where CarGroupOID = '"+OID+"' and ItemOID = '104201310100014' ");		   
							try {

								    rs.next();
								    str = rs.getString("ItemPrice");
								    price15 = rs.getString("ItemPrice")+",";
			
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}      
							et15.setText(df.format(Double.parseDouble(str)));
							 o = Double.parseDouble(str);
		    				}
		    			else {
		    				t15 = 0;
		    				list15 = "";
		    				price15="";
		    				 o = 0;
		    				et15.setText("");
		    				}
		            }
		        });
	     				
	     		
						
						 
						final Calendar c = Calendar.getInstance();
						
				        mYear = c.get(Calendar.YEAR);
				        mMonth = c.get(Calendar.MONTH);
				        mDay = c.get(Calendar.DAY_OF_MONTH); 
				        
						 btn1.setOnClickListener(new View.OnClickListener() {
								public void onClick(View v) {
							if(HoleActivity.CHECH_ADD){					
									rs2 = con.selectData("SELECT MAX(ServiceID) AS maxid FROM CustomerCar WHERE RegisterID = '"+RegisterIDS+"' ");
				    				try {
				    					rs2.next();
				    					ServiceID = rs2.getString("maxid");
				    				} catch (SQLException e1) {
				    					// TODO Auto-generated catch block
				    					e1.printStackTrace();
				    				}
				    				
				    		/*		if (DisCt.equals("��س����͡") || DisCt.equals("")){
				    					DisCt = "-";
				    				}
				    		*/		

				    				if(et16.getText().toString().equals("")){
				       					price16 = "-,";
				    	   				list16 = "-,";
				    				}else{
				    					price16 = et16.getText().toString()+",";
				    	   				list16 = orther1.getText().toString()+",";
				    				}
				    				
				    				if(et17.getText().toString().equals("")){
				    					price17 = "-,";
				    	   				list17 = "-,";
				    				}else{
				    					price17 = et17.getText().toString()+",";
				    	   				list17 = orther2.getText().toString()+",";
				    				}
				    				
				    				if(et18.getText().toString().equals("")){
				    					price18 = "-,";
				    	   				list18 = "-,";
				    				}else{
				    					price18 = et18.getText().toString()+",";
				    	   				list18 = orther3.getText().toString()+",";
				    				}
				    				
				    				
									
									String sql = "INSERT INTO DataService " + 
											"(ServiceID,TypeID,List,price,VIPcode,Discount,amount,Sum,sumTime,date" +
											",DiscountName,PriceBTH,checkOrther) " +
											"VALUES ("+
											"'"+ServiceID+"'" + ',' + 
											"'"+TypeID+"'" + ',' + 
											"'"+list0+list1+list2+list4+list5+list6+list7+list8+list9+
											list10+list11+list12+list13+list14+list15+list16+list17+list18+"'" + ',' + 
											"'"+price0+price1+price2+price4+price5+price6+price7+price8+price9+
											price10+price11+price12+price13+price14+price15+price16+price17+price18+"'" + ',' + 
											"'"+VIPcode+"'" + ',' +
											"'"+sumDisc+"'" + ',' +
											"'"+amount+"'" + ',' +
											"'"+finalSum+"'" + ',' +
											"'"+timeSum+"'" + ',' +
									        "'"+mDay+"/"+(1+mMonth)+"/"+mYear+"'" + "," +
									        "'"+DisCt+"'" + ',' +
									         "'"+sumDisBTH+"'" + ',' +
											"'"+checkOrther1+"'" + ") "; 
									
								     
				    				
				    				
									
								if(con.addData(sql)){	 
								Toast.makeText(services.this, "Inserted data successfully", Toast.LENGTH_SHORT).show();
								//Open Form Add
							Toast.makeText(services.this, ServiceID, Toast.LENGTH_SHORT).show();
								Intent newActivityAdd = new Intent(services.this,Card.class);
								newActivityAdd.putExtra("name", NameInput);
								newActivityAdd.putExtra("CompanyS", company);
								newActivityAdd.putExtra("ServiceID", ServiceID);
								startActivity(newActivityAdd);
								
								}else{
							    Toast.makeText(services.this, "Inserted data fail", Toast.LENGTH_SHORT).show();
							    
							    
								}
								
							   }else{
									
									
									  HoleActivity.CHECH_ADD = true;
									  Toast.makeText(services.this, "���������", Toast.LENGTH_SHORT).show();
									  Intent i = new Intent();
										i.putExtra("time", timeSum+"");
										i.putExtra("Money", finalSum+"");
										i.putExtra("list", list0+list1+list2+list4+list5+list6+list7+list8+list9+
												list10+list11+list12+list13+list14+list15);
										i.putExtra("price", price0+price1+price2+price4+price5+price6+price7+price8+price9+
												price10+price11+price12+price13+price14+price15);
										i.putExtra("name", NameInput);
										i.putExtra("CompanyS", company);
										setResult(HoleActivity.REQUEST_CODE, i);
									    finish();
									   
								}
								
								

								}
								});			
						 
						 
						 
	   			
	}
	
	
	private void orther1() {

		 
		 c16 = ( CheckBox ) this.findViewById ( R.id.check16);	
		 
		 et16 = ( EditText ) this.findViewById ( R.id.result16);
		 et16.setEnabled(false);
		 
		 orther1 = ( EditText ) this.findViewById ( R.id.orther1);
		 orther1.setEnabled(false);
		 
		 c16.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	    			if(c16.isChecked()){
	    				checkOrther1 = "checkOrther";
	    				orther1.setEnabled(true);
	    				et16.setEnabled(true);	
							
							
							
			
				
	    				}
	    			else {
	    				checkOrther1 = "";
	    				p = 0;
	    				orther1.setText("0");
	    				et16.setText("0");
	    				orther1.setEnabled(false);
	    				et16.setEnabled(false);
	    				}
	            }
	        });
}


	private void orther2() {

		 
		 c17 = ( CheckBox ) this.findViewById ( R.id.check17);	
		 
		 et17 = ( EditText ) this.findViewById ( R.id.result17);
		 et17.setEnabled(false);
		 
		 orther2 = ( EditText ) this.findViewById ( R.id.orther2);
		 orther2.setEnabled(false);
		 
		 c17.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
	   			if(c17.isChecked()){
	   				checkOrther1 = "checkOrther";
	   				orther2.setEnabled(true);
	   				et17.setEnabled(true);	
							
							
							
			
				
	   				}
	   			else {
	   				checkOrther2 = "";
	   				q = 0;
	   				orther2.setText("0");
	   				et17.setText("0");
	   				orther2.setEnabled(false);
	   				et17.setEnabled(false);
	   				}
	           }
	       });
	}
	
private void orther3() {

	 
	 c18 = ( CheckBox ) this.findViewById ( R.id.check18);	
	 
	 et18 = ( EditText ) this.findViewById ( R.id.result18);
	 et18.setEnabled(false);
	 
	 orther3 = ( EditText ) this.findViewById ( R.id.orther3);
	 orther3.setEnabled(false);
	 
	 c18.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
 			if(c18.isChecked()){
 				checkOrther1 = "checkOrther";
 				orther3.setEnabled(true);
 				et18.setEnabled(true);	
						
						
						
		
			
 				}
 			else {
 				checkOrther3 = "";
 				r = 0;
 				orther3.setText("0");
 				et18.setText("0");
 				orther3.setEnabled(false);
 				et18.setEnabled(false);
 				}
         }
     });
}


	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		Log.i("Get data", requestCode+"");
	
		switch (requestCode) {
		case services.REQUEST_CODE:
			
			final AlertDialog.Builder dDialog = new AlertDialog.Builder(this);
			
			timeHole = data.getStringExtra("time");
			sumHole = data.getStringExtra("Money");
			listHole = data.getStringExtra("list");
			priceHole = data.getStringExtra("price");
			

			arr = listHole.split(",");
			arr2 = priceHole.split(",");
			
			/*
			    AlertDialog.Builder builder = new AlertDialog.Builder(this);
			    builder.setTitle("dddd");
			    builder .setItems(arr, new DialogInterface.OnClickListener() {
			               public void onClick(DialogInterface dialog, int which) {
			               // The 'which' argument contains the index position
			               // of the selected item
			           }
			    });
			    
			 
				
			//dDialog.setTitle("��¡�������������������� ");
        	//dDialog.setIcon(android.R.drawable.btn_star_big_on); 
			dDialog.setPositiveButton("Close", null);
            dDialog.show();
   zc   */
			  Toast.makeText(services.this,"OMG +"+ timeHole+" "+sumHole+" "+listHole+" "+priceHole, Toast.LENGTH_LONG).show();
			  
			  
			  Sum.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						
						
						
						
						if(et16.getText().toString().equals("")){
							p = 0;
						}else{
						p = Double.parseDouble(et16.getText().toString());
						}
						
						if(et17.getText().toString().equals("")){
							q = 0;
						}else{
						q = Double.parseDouble(et17.getText().toString());
						}
						
						if(et18.getText().toString().equals("")){
							r = 0;
						}else{
						r = Double.parseDouble(et18.getText().toString());
						}
						
				
					
					//////////////  ��ǹŴ�ٻͧ	
						sumDiscNull = disc.getText().toString();
	    				
	    				if(sumDiscNull.equals(null)||sumDiscNull.equals("")){
	    					sumDisc = "0";
	    				}else{
	    					sumDisc = sumDiscNull;
	    				}
	    				sumDisBTHNull = disBTH.getText().toString();
	    				
	    				if(sumDisBTHNull.equals(null)||sumDisBTHNull.equals("")){
	    					sumDisBTH = "0";
	    				}else{
	    					
	    					sumDisBTH = sumDisBTHNull;
	    				}
	    				
	    			////////////////���ǹŴ VIP
	    				VIPcode = prom.getText().toString();
	    				 
	    				 
	    				

						
						timeSum = t0+t1+t2+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15;
						timeSum = timeSum+0;
						Toast.makeText(services.this, "All time is : "+timeSum, Toast.LENGTH_SHORT).show();
						
						
						amount = a0+a+b+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+Double.parseDouble(sumHole);
						 
						SumAmount.setText(String.valueOf(df.format(amount)));
						
						finalSum = (amount-Integer.parseInt(sumDisBTH))-(((amount-Integer.parseInt(sumDisBTH))*Integer.parseInt(sumDisc))/100);
						

	    				TextSum.setText(String.valueOf(df.format(finalSum)));	
	    		
					}
					});
			
			  
			  btn1.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						

						
						rs2 = con.selectData("SELECT MAX(ServiceID) AS maxid FROM CustomerCar WHERE RegisterID = '"+RegisterIDS+"' ");
	    				try {
	    					rs2.next();
	    					ServiceID = rs2.getString("maxid");
	    				} catch (SQLException e1) {
	    					// TODO Auto-generated catch block
	    					e1.printStackTrace();
	    				}
	    				
	    				
	    				
	    				if(et16.getText().toString().equals("")){
	       					price16 = "-,";
	    	   				list16 = "-,";
	    				}else{
	    					price16 = et16.getText().toString()+",";
	    	   				list16 = orther1.getText().toString()+",";
	    				}
	    				
	    				if(et17.getText().toString().equals("")){
	    					price17 = "-,";
	    	   				list17 = "-,";
	    				}else{
	    					price17 = et17.getText().toString()+",";
	    	   				list17 = orther2.getText().toString()+",";
	    				}
	    				
	    				if(et18.getText().toString().equals("")){
	    					price18 = "-,";
	    	   				list18 = "-,";
	    				}else{
	    					price18 = et18.getText().toString()+",";
	    	   				list18 = orther3.getText().toString()+",";
	    				}
						

						
						String sql = "INSERT INTO DataService " + 
								"(ServiceID,TypeID,List,price,VIPcode,Discount,amount,Sum,sumTime,date" +
								",DiscountName,PriceBTH,checkOrther) " +
								"VALUES ("+
								"'"+ServiceID+"'" + ',' + 
								"'"+TypeID+"'" + ',' + 
								"'"+list0+list1+list2+list4+list5+list6+list7+list8+list9+
								list10+list11+list12+list13+list14+list15+listHole+list16+list17+list18+"'" + ',' + 
								"'"+price0+price1+price2+price4+price5+price6+price7+price8+price9+
								price10+price11+price12+price13+price14+price15+priceHole+price16+price17+price18+"'" + ',' + 
								"'"+VIPcode+"'" + ',' +
								"'"+sumDisc+"'" + ',' +
								"'"+amount+"'" + ',' +
								"'"+finalSum+"'" + ',' +
								"'"+timeSum+"'" + ',' +
						        "'"+mDay+"/"+(1+mMonth)+"/"+mYear+"'" + "," +
						        "'"+DisCt+"'" + ',' +
						         "'"+sumDisBTH+"'" + ',' +
								"'"+checkOrther1+"'" + ") "; 
	    				
	    				
						
					if(con.addData(sql)){	 
					Toast.makeText(services.this, "Inserted data successfully ADD HOLE", Toast.LENGTH_SHORT).show();
					//Open Form Add
					Toast.makeText(services.this, ServiceID, Toast.LENGTH_SHORT).show();
					Intent newActivityAdd = new Intent(services.this,Card.class);
					newActivityAdd.putExtra("ServiceID", ServiceID);
					newActivityAdd.putExtra("name", NameInput);
					newActivityAdd.putExtra("CompanyS", company);
					startActivity(newActivityAdd);
					
					}else{
				    Toast.makeText(services.this, "Inserted data fail ADD HOLE", Toast.LENGTH_SHORT).show();
				    
				    
					}
					
					
	        
					
					

					}
					});			
			break;

		default:
			break;
		}	
		
	}


	
	public void selectDis(){
	
	//	String tusTmp = getIntent().getExtras().getString("Status");	
		  spnDis = (Spinner) findViewById(R.id.selectDiscount);
		
		
		
		
		Dis.add("��س����͡");
		Dis.add("����");
		Dis.add("�.�.�.");
		Dis.add("��ǹŴ˹���ҹ");
			
		
		
	ArrayAdapter<String> empolyeeAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Dis);
	empolyeeAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
	spnDis.setAdapter(empolyeeAdapter);

	spnDis.setOnItemSelectedListener(new  AdapterView.OnItemSelectedListener() { 

	public void onItemSelected(AdapterView<?> adapterView, 
		View view, int i, long l) { 
		// TODO Auto-generated method stub
		
		
		DisCt = Dis.get(i);
		
		
		
		}
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		Toast.makeText(services.this,
					String.valueOf("ʶҹ��ա������¹�ŧ����"),
						Toast.LENGTH_SHORT).show();
	} 

	});
	
	}
	
	@Override
 	public void onBackPressed() {
	  
	        new AlertDialog.Builder(this)
	        .setTitle("¡��ԡ��÷���¡��")
	        .setMessage("��Ѻ�˹����ѡ")
	                .setNegativeButton(android.R.string.yes, new DialogInterface.OnClickListener() {

	                    public void onClick(DialogInterface arg0, int arg1) {
	                        Intent newActivity = new Intent(getApplicationContext(),MainActivity.class);	                          
	                        newActivity.putExtra("name", NameInput);
							newActivity.putExtra("CompanyS", company);
	                        startActivity(newActivity);
	                        finish();
	                        overridePendingTransition(R.layout.fadeendout,R.layout.fadeendin);
	                    }
	                })
	                .setPositiveButton(android.R.string.no, null).create().show();
	    

	}
	

}
